﻿// SetPenBrush.cpp : 实现文件
//

#include "stdafx.h"
#include "CAD.h"
#include "SetPenBrush.h"
#include "afxdialogex.h"


// CSetPenBrush 对话框

IMPLEMENT_DYNAMIC(CSetPenBrush, CDialogEx)

CSetPenBrush::CSetPenBrush(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG1, pParent)
    , m_SPenWidth(1)
{
    m_SavePenStyle = 0;
    m_SavePenColor = RGB(0, 0, 0);

    m_SaveBrushStyle = 0;
    m_SaveBrushHatch = 0;
    m_SaveBrushColor = RGB(255, 255, 255);
}

CSetPenBrush::~CSetPenBrush()
{
}

void CSetPenBrush::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_COMBO1, m_PenStyle);
    DDX_Control(pDX, IDC_SLIDER2, m_PenWidth);
    DDX_Control(pDX, IDC_MFCCOLORBUTTON1, m_PenColor);
    DDX_Text(pDX, STAC_PENWIDTH, m_SPenWidth);
    DDV_MinMaxInt(pDX, m_SPenWidth, 1, 99);
    DDX_Control(pDX, IDC_COMBO2, m_BrushStyle);
    DDX_Control(pDX, IDC_COMBO3, m_BrushHatch);
    DDX_Control(pDX, IDC_MFCCOLORBUTTON2, m_BrushColor);
}


BEGIN_MESSAGE_MAP(CSetPenBrush, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON1, &CSetPenBrush::OnBnClickedButton1)
    ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER2, &CSetPenBrush::OnReleasedcaptureSlider2)
    ON_CBN_SELCHANGE(IDC_COMBO2, &CSetPenBrush::OnSelchangeCombo2)
END_MESSAGE_MAP()


// CSetPenBrush 消息处理程序


void CSetPenBrush::SetSavePenStyle(int SavePenStyle)
{
    m_SavePenStyle = SavePenStyle;
}

int CSetPenBrush::GetSavePenStyle() const
{
    return m_SavePenStyle;
}

void CSetPenBrush::SetSavePenColor(COLORREF SavePenColor)
{
    m_SavePenColor = SavePenColor;
}

COLORREF CSetPenBrush::GetSavePenColor() const
{
    return m_SavePenColor;
}

void CSetPenBrush::SetSavePenWidth(int SavePenwidth)
{
    m_SPenWidth = SavePenwidth;
}

int CSetPenBrush::GetSavePenWidth() const
{
    return m_SPenWidth;
}

void CSetPenBrush::SetSaveBrushStyle(int SaveBrushStyle)
{
    m_SaveBrushStyle = SaveBrushStyle;
}

int CSetPenBrush::GetSaveBrushStyle() const
{
    return m_SaveBrushStyle;
}

void CSetPenBrush::SetSaveBrushHatch(int SaveBrushHatch)
{
    m_SaveBrushHatch = SaveBrushHatch;
}

int CSetPenBrush::GetSaveBrushHatch() const
{
    return m_SaveBrushHatch;
}

void CSetPenBrush::SetSaveBrushColor(COLORREF SaveBrushColor)
{
    m_SaveBrushColor = SaveBrushColor;
}

COLORREF CSetPenBrush::GetSaveBrushColor() const
{
    return m_SaveBrushColor;
}

BOOL CSetPenBrush::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    //设置默认画笔线粗
    m_PenWidth.SetRange(1, 99);
    m_PenWidth.SetPos(m_SPenWidth);

    //向控件中添加画笔风格
    m_PenStyle.AddString("实    线(______)");
    m_PenStyle.AddString("虚    线(------)");
    m_PenStyle.AddString("点    线(......)");
    m_PenStyle.AddString("点 画 线(-.-.-.)");
    m_PenStyle.AddString("点点画线(-..-..)");
    m_PenStyle.AddString("空 画 笔(      )");

    //设置默认画笔风格
    m_PenStyle.SetCurSel(m_SavePenStyle);

    //设置画笔默认颜色
    m_PenColor.SetColor(m_SavePenColor);

    //设置默认画刷风格
    m_BrushStyle.AddString("实心");
    m_BrushStyle.AddString("空心");
    m_BrushStyle.AddString("填充");

    m_BrushStyle.SetCurSel(m_SaveBrushStyle);

    //设置填充的风格
    m_BrushHatch.AddString("------------");
    m_BrushHatch.AddString("|||||||||||");
    m_BrushHatch.AddString("\\\\\\\\\\\\\\\\\\\\\\\\\\");
    m_BrushHatch.AddString("//////////////");
    m_BrushHatch.AddString("++++++++");
    m_BrushHatch.AddString("xxxxxxxxxx");

    m_BrushHatch.SetCurSel(m_SaveBrushHatch);

    //设置画刷默认颜色
    m_BrushColor.SetColor(m_SaveBrushColor);

    if (m_BrushStyle.GetCurSel() != 2)
    {
        m_BrushHatch.EnableWindow(FALSE);
    }

    UpdateData(FALSE);

    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}


void CSetPenBrush::OnBnClickedButton1()
{
    UpdateData(TRUE);

    m_SavePenStyle = m_PenStyle.GetCurSel();
    m_SavePenColor = m_PenColor.GetColor();
    m_SaveBrushStyle = m_BrushStyle.GetCurSel();
    m_SaveBrushHatch = m_BrushHatch.GetCurSel();
    m_SaveBrushColor = m_BrushColor.GetColor();

    EndDialog(IDOK);
}


//响应Slider控件的滑动
void CSetPenBrush::OnReleasedcaptureSlider2(NMHDR *pNMHDR, LRESULT *pResult)
{
    *pResult = 0;

    //更新画笔的宽度
    m_SPenWidth = m_PenWidth.GetPos();
    UpdateData(FALSE);
}


void CSetPenBrush::OnSelchangeCombo2()
{
    int nSelect = m_BrushStyle.GetCurSel();

    switch (nSelect)
    {
    case 0:
    {
        m_BrushColor.EnableWindow(TRUE);
        m_BrushHatch.EnableWindow(FALSE);
        break;
    }
    case 1:
    {
        m_BrushColor.EnableWindow(FALSE);
        m_BrushHatch.EnableWindow(FALSE);
        break;
    }
    case 2:
    {
        m_BrushColor.EnableWindow(TRUE);
        m_BrushHatch.EnableWindow(TRUE);
        break;
    }
    }
}
